import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:yysk_app/model/collection_model/my_collection_list_by_collection_id_model.dart';
import 'package:yysk_app/pages/nft_pages/home_pages/my_collection_detail/my_collection_detail_page.dart';
import 'package:yysk_app/pages/nft_pages/home_pages/my_collection_list/my_collection_list_controller.dart';
import 'package:yysk_app/utils/colors.dart';
import 'package:yysk_app/utils/helper.dart';
import 'package:yysk_app/widget/image_asset_widget.dart';
import 'package:yysk_app/widget/lazy_network_image.dart';
import 'dart:math';

class MyCollectionListItemWidget extends StatelessWidget {
  final MyCollectionListByCollectionIdItem item;
  final int index;
  const MyCollectionListItemWidget({
    super.key,
    required this.item,
    required this.index,
  });

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        MyCollectionListController controller = Get.find();
        Get.toNamed(
          "${MyCollectionDetailPage.path}?id=${item.id}&headPrice=${controller.headDetail.value?.totalPriceLimit}&serviceCharge=${controller.headDetail.value?.serviceCharge}",
          arguments: {
            'id': item.id,
            'headPrice': '${controller.headDetail.value?.totalPriceLimit}',
            'serviceCharge': '${controller.headDetail.value?.serviceCharge}',
          },
        );
      },
      child: Container(
        width: context.width,
        margin: const EdgeInsets.only(bottom: 12),
        clipBehavior: Clip.antiAlias,
        decoration: BoxDecoration(
          color: Color.fromRGBO(31, 33, 38, 1),
          borderRadius: BorderRadius.circular(6.px),
          boxShadow: [
            BoxShadow(
              color: AppColors.backgroundColorBlack.withAlpha(25),
              offset: const Offset(0, 14),
              blurRadius: 24,
              spreadRadius: 0,
            ),
          ],
        ),
        child: Stack(
          children: [
            Column(
              mainAxisAlignment: MainAxisAlignment.start,
              // crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Stack(
                  children: [
                    LazyImage(
                      imageUrl: '${item.coverImageUrl}',
                      width: context.width,
                      boxFit: BoxFit.fitWidth,
                      height: 166.px,
                      alignment: Alignment.topCenter,
                      borderRadius: 0,
                    ),

                    Positioned(
                      left: 0.px,
                      top: 0.px,
                      right: 0,
                      child: Container(
                        padding: EdgeInsets.only(left: 14.px, right: 14.px),
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(0.px),
                        ),
                        child: Center(
                          child: Stack(
                            children: [
                              if (item.chainStatus == 'WAITING' &&
                                  item.isLockedHouse == false)
                                ImageAssetWidget(
                                  imageUrl: 'static/images/mine/b1.png',
                                  width: 72.px,
                                  height: 16.px,
                                  fit: BoxFit.fitWidth,
                                  alignment: Alignment.topCenter,
                                ),
                              if (item.chainStatus != 'WAITING' &&
                                  item.isOnSale == true &&
                                  item.isLockedHouse == false)
                                ImageAssetWidget(
                                  imageUrl: 'static/images/mine/b2.png',
                                  width: 72.px,
                                  height: 16.px,
                                  fit: BoxFit.fitWidth,
                                  alignment: Alignment.topCenter,
                                ),
                              if (item.chainStatus != 'WAITING' &&
                                  item.isOnSale != true &&
                                  item.isLockedHouse == false)
                                ImageAssetWidget(
                                  imageUrl: 'static/images/mine/b3.png',
                                  width: 72.px,
                                  height: 16.px,
                                  fit: BoxFit.fitWidth,
                                  alignment: Alignment.topCenter,
                                ),
                              if (item.isLockedHouse == false)
                                SizedBox(
                                  width: 72.px,
                                  height: 16.px,
                                  child: Text(
                                    item.chainStatus == 'WAITING'
                                        ? '上链中'
                                        : item.isOnSale == true
                                        ? '寄售中'
                                        : item.collectionEquity == 'INCUBATION'
                                        ? '孵化中'
                                        : '持有中',
                                    style: TextStyle(
                                      color: AppColors.fontColorBlack,
                                      fontSize: 10.px,
                                    ),
                                    textAlign: TextAlign.center,
                                  ),
                                ),
                            ],
                          ),
                        ),
                      ),
                    ),
                    if (item.isLockedHouse == true)
                      Positioned(
                        left: 0.px,
                        top: 0.px,
                        right: 0,
                        bottom: 0,
                        child: Container(
                          padding: EdgeInsets.only(left: 14.px, right: 14.px),
                          decoration: BoxDecoration(
                            color: Color.fromRGBO(0, 0, 0, 0.6),
                            // borderRadius: BorderRadius.circular(6.px),
                          ),
                          child: Center(
                            child: Text(
                              '解锁时间 \n${item.lockedPositionTime}',
                              style: TextStyle(color: AppColors.fontColor),
                              textAlign: TextAlign.center,
                            ),
                          ),
                        ),
                      ),
                  ],
                ),
                Padding(
                  padding: EdgeInsets.fromLTRB(10.px, 0.px, 10.px, 0),
                  child: SizedBox(
                    width: context.width,
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.start,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        SizedBox(height: 6.px),
                        Row(
                          crossAxisAlignment: CrossAxisAlignment.center,
                          mainAxisAlignment: MainAxisAlignment.start,
                          children: [
                            Row(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                Text(
                                  '￥',
                                  style: TextStyle(
                                    color: AppColors.startColor,
                                    fontSize: 13.px,
                                  ),
                                  textAlign: TextAlign.left,
                                ),
                                Text(
                                  '${item.buyPrice}',
                                  style: TextStyle(
                                    color: AppColors.startColor,
                                    fontSize: 20.px,
                                  ),
                                  textAlign: TextAlign.left,
                                ),
                              ],
                            ),
                            SizedBox(width: 8.px),
                            Container(
                              decoration: BoxDecoration(
                                // color: AppColors.backgroundColorBlack,
                                borderRadius: BorderRadius.circular(4.px),
                              ),
                              child: Center(
                                child: Text(
                                  '买入价',
                                  style: TextStyle(
                                    color: AppColors.backgroundColorGrey,
                                    fontSize: 12.px,
                                  ),
                                  textAlign: TextAlign.center,
                                ),
                              ),
                            ),
                          ],
                        ),

                        if (item.chainStatus != 'WAITING' &&
                            item.collectionEquity == 'INCUBATION')
                          Row(
                            children: [
                              Container(
                                padding: EdgeInsets.only(
                                  left: 4.px,
                                  right: 0.px,
                                ),
                                decoration: BoxDecoration(
                                  borderRadius: BorderRadius.circular(2.px),
                                  color: Color.fromRGBO(59, 62, 69, 1),
                                  border: Border.all(
                                    width: 1.px,
                                    color: Color.fromRGBO(59, 62, 69, 1),
                                  ),
                                ),
                                child: Center(
                                  child: Row(
                                    children: [
                                      Text(
                                        '孵化天数',
                                        style: TextStyle(
                                          color: AppColors.fontColor,
                                          fontSize: 12.px,
                                        ),
                                        textAlign: TextAlign.left,
                                        overflow: TextOverflow.ellipsis,
                                      ),
                                      SizedBox(width: 4.px),
                                      Container(
                                        padding: EdgeInsets.only(
                                          left: 4.px,
                                          right: 4.px,
                                        ),
                                        decoration: BoxDecoration(
                                          color: Color.fromRGBO(31, 33, 38, 1),
                                          borderRadius: BorderRadius.only(
                                            topRight: Radius.circular(2.px),
                                            bottomRight: Radius.circular(2.px),
                                          ),
                                        ),
                                        child: Text(
                                          (item.incubationDays ?? 0) >= 0
                                              ? '剩余${(item.incubationDays ?? 0)}天'
                                              : '超期${(0 - int.parse('${item.incubationDays}'))}天',
                                          style: TextStyle(
                                            color:
                                                item.incubationDays == 0
                                                    ? AppColors.fontColorPurple
                                                    : (item.incubationDays ??
                                                            0) >
                                                        0
                                                    ? AppColors.fontColor
                                                    : (item.incubationDays ??
                                                            0) ==
                                                        0
                                                    ? AppColors.fontColorPurple
                                                    : AppColors.fontColorRed2,
                                            fontSize: 10.px,
                                          ),
                                        ),
                                      ),
                                    ],
                                  ),
                                ),
                              ),
                            ],
                          ),
                      ],
                    ),
                  ),
                ),
              ],
            ),
            if (item.tokenId != null)
              Positioned(
                right: 0.px,
                top: 129.px,
                child: Container(
                  height: 26.px,
                  padding: EdgeInsets.only(left: 14.px, right: 14.px),
                  decoration: BoxDecoration(
                    color: Color.fromRGBO(0, 0, 0, 0.5),
                    borderRadius: BorderRadius.only(
                      topLeft: Radius.circular(100),
                      bottomLeft: Radius.circular(100),
                    ),
                  ),
                  child: Center(
                    child: Text(
                      '#${item.tokenId}',
                      style: TextStyle(color: AppColors.fontColor),
                    ),
                  ),
                ),
              ),
          ],
        ),
      ),
    );
  }
}
